$(".small-box").hover(function () {
    $(".mask").show();
    $(".big-box").show();
}, function () {
    $(".mask").hide()
    $(".big-box").hide()
})

$(".small-box").mousemove(function (e) {
    let s = e.pageX - $(".small-box").offset().left - $(".mask").width() / 2;
    let t = e.pageY - $(".small-box").offset().top - $(".mask").height() / 2;
    if (s < 0) {
        s = 0
    }
    if (s > $(".small-box").innerWidth() - $(".mask").outerWidth()) {
        s = $(".small-box").innerWidth() - $(".mask").outerWidth()
    }
    if (t <= 0) {
        t = 0
    }
    if (t > $(".small-box").innerWidth() - $(".mask").outerWidth()) {
        t = $(".small-box").innerWidth() - $(".mask").outerWidth()
    }

    $(".mask").css("left", s + "px")
    $(".mask").css("top", t + "px")




    $(".big-box").css("background-position-x", -s + "px")
    $(".big-box").css("background-position-y", -t + "px")

});




//==========================================================================

$(function () {
    let cookie = getCookie("username");
    console.log(cookie);
    let ids = location.search.split('=')[1];
    console.log(ids);

    // console.log(name);

    getGoodsInfo(ids);
    // getAddShoppingCart(ids);
    $(".boxs .massage .chart").on("click", ".goshopcar", function () {
        let cookie = getCookie("username");
        getAddShoppingCart(cookie, ids)

    })
})



// 根据id渲染商品信息

function getGoodsInfo(ids) {

    $.get("../goodsAndShoppingCart/getGoodsInfo.php", { "goodsId": ids },
        function (data) {
            let arr = JSON.parse(data);
            console.log(arr);
            $(".boxs .small-box img").prop("src", arr.goodsImg);
            $(".massage .mas .goodsName").html(arr.goodsName);
            $(".massage .mas .goodsPrice").html(arr.goodsPrice);
            $(".num p").html(arr.goodsCount);
            $(".massage .pict").html(arr.goodsDesc);

        });
}



function getAddShoppingCart(cookie, goodsid) {
    if (cookie != "") {
        $.post("../goodsAndShoppingCart/addShoppingCart.php", { "vipName": cookie, "goodsId": goodsid, "goodsCount": '1' },
            function (data) {
                console.log(data);
                if (data.trim() == "1") {
                    alert("添加成功")
                    location.href = "./shoppingcar.html";
                } else {
                    alert("添加失败")
                }
            })
    } else {
        alert("请先登录")
    }

}